package com.wjs.blog.admin.Service;

import com.wjs.blog.admin.pojo.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Component
public class SecurityUserService implements UserDetailsService {
    @Autowired
    private AdminService service;
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        Admin admin = this.service.FindAdminByUsername(s);
        if(admin==null){
            return null;
        }
        UserDetails userDetails=new User(s, admin.getPassword(), new ArrayList<>());
        System.out.println(admin.getPassword());
        return userDetails;
    }
}
